<?php
class TestView extends TPage
{
    /**
     * Constructor method
     */
    public function __construct()
    {
        parent::__construct();
        $form = new TQuickForm;
        $form->addQuickAction('Contacts', new TAction(array($this, 'onContacts')), 'ico_view.png');
        $form->addQuickAction('Skills', new TAction(array($this, 'onSkills')), 'ico_view.png');
        $this->html = new THtmlRenderer('app/resources/content.html');

        $table = new TTable;
        $table->addRow()->addCell($form);
        $table->addRow()->addCell($this->html);
        
        TTransaction::open('samples');
        $obj = new Customer(1);
        TTransaction::close();
        
        $replace = array();
        $replace['name']    = $obj->name;
        $replace['address'] = $obj->address;
                         
        $this->html->setReplacements($replace);
        parent::add($table);
    }
    
    /**
     * Executed when the user clicks at the contacts button
     */
    public function onContacts()
    {
        TTransaction::open('samples');
        $obj = new Customer(1);
        $contacts = $obj->getContacts();
        TTransaction::close();
        
        $replace = array();
        foreach ($contacts as $contact)
        {
            $replace[] = array('type' => $contact->type, 'value'=> $contact->value);
        }
        
        $this->html->enableSection('contacts');
        $this->html->enableSection('contacts-detail', TRUE);
        $this->html->setReplacements($replace, 'contacts-detail');
    }
    
    /**
     * Executed when the user clicks at the skills button
     */
    public function onSkills()
    {
        TTransaction::open('samples');
        $obj = new Customer(1);
        $skills = $obj->getSkills();
        TTransaction::close();
        
        $replace   = array();
        foreach ($skills as $skill)
        {
            $replace[] = array('skill' => $skill->name);
        }
        
        $this->html->enableSection('skills');
        $this->html->enableSection('skills-detail', TRUE);
        $this->html->setReplacements($replace, 'skills-detail');
    }
}
?>